package vinicorp.dolphin.mediaplayer;

import vinicorp.dolphin.mediaplayer.R;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ServicesDemo extends Activity implements OnClickListener {
	private static final String TAG = "ServicesDemo";
	protected static final String LOG_TAG = null;
	Button buttonStart;
	boolean isPlay = false;
	protected ServiceConnection mServerConn = new ServiceConnection() {
		@Override
		public void onServiceConnected(ComponentName name, IBinder binder) {
			Log.d(LOG_TAG, "onServiceConnected");
		}

		@Override
		public void onServiceDisconnected(ComponentName name) {
			Log.d(LOG_TAG, "onServiceDisconnected");
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		buttonStart = (Button) findViewById(R.id.buttonStart);
		Button btnBind = (Button) findViewById(R.id.btnBind);
		Button btnUnBind = (Button) findViewById(R.id.btnUnbind);
		buttonStart.setOnClickListener(this);
		btnBind.setOnClickListener(this);
		btnUnBind.setOnClickListener(this);

	}

	public void onClick(View src) {
		switch (src.getId()) {
		case R.id.buttonStart:
			if (isPlay) {
				buttonStart.setText("Start");
				stopService(new Intent(this, MyService.class));
			} else {
				buttonStart.setText("Stop");
				startService(new Intent(this, MyService.class));
			}
			isPlay = !isPlay;
			break;
		case R.id.btnBind:
			bindService(new Intent(this, MyService.class), mServerConn,
					Context.BIND_AUTO_CREATE);

			break;
		case R.id.btnUnbind:

			unbindService(mServerConn);
			break;
		}
	}
}